﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Comod_GiftsAdd : ATPages
{
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lblDate.Text = DateTime.Now.ToShortDateString();
            lblName.Text = Server.UrlDecode(Request.Cookies["user"].Values["realname"]);
            lblPath.Text = f.getModuleidAdd(Request["moduid"]);
          
                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    initData();
                }
          
        }
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        ZSql zs = new ZSql();
        if (Request["action"] == "add")
        {
            zs.Open("update CS_Gifts set Num=Num+" + txtNum.Value + ",Price=" + txtCmoney.Value + ",TotalMoney=TotalMoney+" + txtToTal.Value + " where giftsId=" + Request["id"]);
        }
        if (Request["action"] == "edit")
        {
            zs.Open("update CS_Gifts set Num=" + txtNum.Value + ",Price=" + txtCmoney.Value + ",TotalMoney=" + txtToTal.Value + ",GiftsName='" + txtName.Text + "',EditName='" + lblName.Text + "',EditDate='" + lblDate.Text + "',Content='" + txtContent.Text + "' where giftsId=" + Request["id"]);
        }
        if (Request["action"] == "ad")
        {
            zs.Open("insert into CS_Gifts(GiftsName,Num,Price,TotalMoney,EditName,EditDate,Content)values('" + Common.FormatParameter(txtName.Text) + "'," + txtNum.Value + "," + txtCmoney.Value + "," + txtToTal.Value + ",'" + lblName.Text + "','" + lblDate.Text + "','" + Common.FormatParameter(txtContent.Text) + "')");
        }
        zs.Close();

        Response.Redirect("Gifts.aspx?moduid=" + Request["moduid"]);
    }
    private void initData()
    {
        ZSql zs = new ZSql();
        zs.Open("select * from CS_Gifts where giftsId=" + Request["id"]);
        if (Request["action"] == "add")
        {

            txtName.Text = zs.m_table.Rows[0]["GiftsName"].ToString();
        }
        if (Request["action"] == "edit")
        {
            txtName.Text = zs.m_table.Rows[0]["GiftsName"].ToString();
            txtNum.Value = zs.m_table.Rows[0]["Num"].ToString();
            txtCmoney.Value = zs.m_table.Rows[0]["Price"].ToString();
            txtToTal.Value = zs.m_table.Rows[0]["TotalMoney"].ToString();
            txtContent.Text = zs.m_table.Rows[0]["Content"].ToString();
        }



    }
}
